const { promisify} = require('util')
const figlet = promisify(require('figlet'))
const clear = require('clear')
const chalk = require('chalk')
const {clone} = require('./download')
const log = content => console.log(chalk.green(content))
// const {spawn} = require('child_process')

const spawn = async(...args)=>{
	const {spawn} = require('child_process')
	return new Promise(resolve=>{
		const proc  = spawn(...args)
		proc.stdout.pipe(process.stdout)
		proc.stderr.pipe(process.stderr)
		proc.on('close',()=>{
			resolve()
		})
	})
}
module.exports = async name =>{
	clear()
	const data = await figlet('KKB  YYDS')
	log(data)
	
	log("创建项目"+name)
	await clone('github:su37josephxia/vue-template', name)
	
	spawn('npm', ['install'])
	
	log("安装依赖。。。")
	
	log(chalk.green(`
		安装完成
		cd ${name}
		npm run serve
	`))
	open('http://localhost:8080')
	await spawn('npm',['install'],{cwd:`./${name}`})
}